The format argument consists of one or more codes; each formatting code is preceded by a percent sign (%). Characters not prefixed with a percent sign copied unchanged to the output buffer. Any character following a percent sign is not recognized as a valid format code is copied unchanged to the destination. Therefore, you can enter %% to include the percent sign in the resulting output string.
You can use these format codes:
Code |
Description |
%d |
Day of month as decimal number (01 – 31) |
%H |
Hour in 24-hour format (00 – 23) |
%I |
Hour in 12-hour format (01 – 12) |
%m |
Month as decimal number (01 – 12) |
%M |
Minute as decimal number (00 – 59) |
%p |
Current locale's AM/PM indicator for 12-hour clock |
%S |
Second as decimal number (00 – 59) |
%y |
Year without century, as decimal number (00 – 99) |
%Y |
Year with century, as decimal number |
%A |
Weekday name, such as Tuesday |
%b |
Abbreviated month name, such as Mar |
%B |
Full month name, such as March |
%j |
Day of year as decimal number, such as 001–366 |
%w |
Weekday as decimal number, such as 1 – 7 with Sunday as 1 |
%@xxx |
Specify language locale (Where xxx identifies one of the supported languages. For example. A format of %@CAD%A might produce mardi, the French word for Tuesday.) |
Here are some examples:
Format |
Output |
%m-%d-%Y |
01-01-2009 |
The year is %Y. |
The year is 2009. |
Born %m/%d/%y at %I:%M %p |
Born 01/01/09 at 11:57 PM |
An octothorp (#) tells the system to suppress leading zeros for the following format codes. This flag is recognized on these formats and is ignored on all other format codes not listed here.
%#d, %#H, %#I, %#j, %#m, %#M, %#S, %#w
For example, if %d outputs 01, using %#d the output will become 1.
Note | This flag only affects the format code that specifies it. Any subsequent codes that are numeric are not affected unless they also specify the flag. |
Enter a greater than symbol (>) to uppercase the resulting text. This flag is only recognized on these format codes:
%>p, %>A, %>b, %>B
For example, if %A results in Tuesday, %>A produces TUESDAY.
Note | This flag only affects the format code that specifies it. Any subsequent codes that have text are not affected unless those also specify the flag. |
Enter a less than symbol (<) to lowercase the resulting text. This flag is valid for the following codes and ignored on all others:
%<p, %<A, %<b, %<B
For example, if %b results in Mar, %<b produces mar.
Note | This flag only affects the format code that specifies it. Any subsequent codes that have text are not affected unless they also specify the flag. |
Enter <> to capitalize the first letter of the resulting text. This flag is valid for the following codes and ignored on all others:
%<>p, %<>A, %<>b, %<>B
For example, if %p results in AM, %<>p produces Am.
Note | This flag only affects the format code that specifies it. Any subsequent codes that have text are not affected unless they also specify the flag. |
© Copyright 2014, Oracle and/or its affiliates. All rights reserved. Legal notices.